﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Lenovo.CFI.BLL;
using Lenovo.CFI.Common;
using Lenovo.CFI.Web.Helper;
using Lenovo.CFI.BLL.Sys;
using Lenovo.CFI.BLL.DicMgr;
using Lenovo.CFI.Common.Sys;

namespace Lenovo.CFI.Web.VP
{
    public partial class SearchApply : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int? id = UrlHelper.GetQueryStringToInt("id");
                Idea idea = null;
                if (id.HasValue) idea = new IdeaBl().GetIdeaById(id.Value);
                if (idea == null) ErrorHelper.RaiseNoValueError();

                ViewState["id"] = id;

                this.TxtTitle.Text = idea.Title;
            }
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                new UserIdeaAppBl().Apply(UserHelper.UserName, (int)ViewState["id"], this.TxtReason.Text);

                this.BtnSave.Visible = false;

                MessageHelper.Show("Success!", this.Page);

                System.Web.UI.ScriptManager.RegisterStartupScript(this.BtnSave, this.Page.GetType(), "Close",
    @"setTimeout(""window.close();"", 1000);", true);

            }
            catch (ApplicationException ex)
            {
                MessageHelper.RegShowJS(ex.Message, this.Page);
            }
        }
    }
}